<template>
  <el-row style="height:100%">
    <page>
      <pageheader :isShow="false">
        许可证授权
      </pageheader>
      <div class="page-content">
        <el-card class="box-card">
          <p style="margin-bottom: 20px">授权过期时间：{{time}}</p>
          <div class="block">
            <span class="demonstration">授权时间：</span>
            <el-date-picker
              v-model="exp_time"
              type="datetime"
              value-format="yyyy-MM-dd HH:mm:ss"
              format="yyyy-MM-dd HH:mm:ss"
              placeholder="选择日期时间">
            </el-date-picker>
          </div>
          <el-button @click="setExpTime" type="primary">授权</el-button>
        </el-card>
      </div>
    </page>
  </el-row>
</template>

<script>
  import page from "@/components/page/page";
  import pageheader from "@/components/page/pageheader";
  export default {
    data() {
      return {
        exp_time:'',
        time:''
      }
    },
    components: {
      page,
      pageheader,
    },
    created(){

    },
    mounted(){
      this.getExpTime()
    },
    methods:{
      getExpTime(){
        let url = '/licence/get_exp_time'
        this.$api.get(url)
        .then(data=>{
          if(data == '10001'){
            this.$message.error('无权操作该数据')
            this.$Bus.$emit('Loading',false);
            return
          }
          if(data){
            this.time = data.data
          }
          this.$Bus.$emit('Loading',false)
        })
        .catch(err=>{
           console.log(err);
          this.$Bus.$emit('Loading',false)
        })
      },
      setExpTime(){
        this.$Bus.$emit('Loading',true)
        let url = '/licence/set_exp_time?exp_time=' + this.exp_time
        this.$api.post(url)
        .then(data=>{
          if(data == '10001'){
            this.$message.error('无权操作该数据')
            this.$Bus.$emit('Loading',false);
            return
          }
          if(data){
            this.$message({
              message: "授权成功",
              type: "success"
            });
            this.getExpTime()
          }
          this.$Bus.$emit('Loading',true)
        })
        .catch(err=>{
           console.log(err);
          this.$Bus.$emit('Loading',false)
        })
      }
    }
  }
</script>

<style>
</style>